﻿module LineRenderingTest

open NUnit.Framework
open Dom
open Layout
open Lines
open StyledElements
open MockDisplayElements
open Boxes
open Floats

[<TestFixture>]
type testLineBreaking() =    

    let callback (elem:IStyledElement) ((width,height):(int * int option)) (layers:Layers) : Layout * Layers =
        ElementBoxLayout(BoxSize(100,100), elem, []), layers    

    [<Test>]
    member self.toLineBoxesSingleLine() =
        let units = [
            WordUnit("test", SText("test test"))
            WordUnit("test", SText("test test"))
            ]            
        let lines, layers, flow = toLines callback units (1000,None) (Flow([],[])) (FloatOffset(0,0,0)) (Layers([]))
        Assert.AreEqual(1, lines.Length)

    [<Test>]
    member self.toLineBoxesMultiline() =
        // each letter have a width of ll
        // so with a line width of 100 we should get two lines
        let node = SText("test test test")
        let units = [
            WordUnit("test ", node)
            WordUnit("test ", node)
            WordUnit("test", node)
            ]            
        let lines, layers, flow = toLines callback units (100,None) (Flow([],[])) (FloatOffset(0,0,0)) (Layers([]))
        Assert.AreEqual(2, lines.Length)
        let (Line(line2units,l,r,y)) = lines.[1]  
        Assert.AreEqual(1, line2units.Length)

    [<Test>]
    member self.toLineBoxesFloat() =
        let units = [
            WordUnit("test", SText("test test"))
            Float(SElement("", [SText("xyz")]), true)
            WordUnit("test", SText("test test"))
            ]            
        let lines, flow, layers = toLines callback units (1000,None) (Flow([],[])) (FloatOffset(0,0,0)) (Layers([]))
        Assert.AreEqual(1, lines.Length)
        let (Line(units,left,right,y)) = lines.[0]
        let (Flow(leftFloats,rightFloats)) = flow
        Assert.AreEqual(1, leftFloats.Length)
        Assert.AreEqual(0, rightFloats.Length)
        let (x,y), layout = leftFloats.[0]
        Assert.AreEqual(0, x)
        
        